/*
 **画材全免费计划板块JS
*/

/* 新参与人数自动回滚特效 */
$(function(){
    $('.wufeng').eq(1).html($('.wufeng').eq(0).html()); //把第二个wufeng标签赋值为第一个的内容
    setInterval("wufeng()",30);  //每过30毫秒执行一次wufeng()方法；
});
function wufeng(){
    var top0 = parseInt($('.wufeng').eq(0).position().top); //获取第一个wufeng标签的top值
    var top1 = parseInt($('.wufeng').eq(1).position().top);   //获取第二个wufeng标签的top值
    if (top0 == -2500) {
        $('.wufeng').eq(0).css('top','2500px');//当第一个wufeng标签的top值为-2500的时候重新赋值，让它在下面连续
    }else{
        $('.wufeng').eq(0).css('top',top0-1+'px');//否则它的top一直减1Px，往上跑的效果
    }
    if (top1 == -2500) {
        $('.wufeng').eq(1).css('top','2500px');//当第二个wufeng标签的top值为-2500的时候重新赋值，让它在下面连续
    }else{
        $('.wufeng').eq(1).css('top',top1-1+'px');//否则它的top一直减1Px，往上跑的效果
    }
}

/* 加载完成2.5m后查分入口高度变0 */
$(document).ready(function(){
    setTimeout(function(){
        $("#freeplan_check_points_entry").animate({"height":"0px"},1000);
    },4000);
    setTimeout(function(){
        $("#registration .check_points_entry").animate({"marginTop":"0px"},1000);
    },5000);
});


/* 视频评论版块JS */
$(document).ready(function(){
    $('#video_comments .video_com .video_big').click(function(){
        $('#video_comments .video_com .bg').hide();
        $('#video_comments .video_com .button').hide();
        $('#video_comments .video_com .big_video').show();
    });
});


function check(obj){
    /* 判断勾选状态 */
    if(!$(obj).hasClass("select")){
        $(obj).addClass("select");
        $("#next_but").attr("class","next_but");
    }else{
        $(obj).removeClass("select");
        $("#next_but").attr("class","no_next");
    }
}
/* 阅读协议点击下一步 */
function next_but(){
    if($("#next_but").hasClass("next_but")){
        $('#agreement_mask').css('display','none'); 
        $('#agreement').css('display','none');
    }
}    


/* 滚动距离头部多少像素时触发相关事件 */
$(document).scroll(function(){
    /* 滚动条距头部300像素时隐藏查分大入口 */
    if($(document).scrollTop()>300){
        $("#freeplan_check_points_entry").hide();
        $("#registration .check_points_entry").animate({"marginTop":"0px"},1000);
    }
    /* 滚动条距头部600像素显示头部跟随 */
    if($(document).scrollTop()<600){
        $("#afterbody_follow").removeClass('show');
    }else{
        $("#afterbody_follow").addClass('show');
    }
    /* 滚动条距头部1020像素显示视频缩放 */
    if($(document).scrollTop()>1020){
        $('#video_comments .video_com .video_big .bg').animate({width:'905px',height:'443px',left:'50%',top:'50%',marginLeft:'-452.5px',marginTop:'-221.5px'},3000);  
    }
});

/* 九大美院点赞区点赞ajax */
function toupiao(num,obj){
    if(10>num>0){
        $('#arts_academy__praise .box_list .big_box .toupiao').removeAttr("onclick");
            $("#arts_academy__praise .box_list .big_box .toupiao").attr('onclick','').click(
                function(){
                    Ctf("你已经投过票了，谢谢您的参与");
                }
            );
        var url = 'freeplan.php?act=academy_toupiao';
        $.ajax({url:url,data:{id:num},type:'post',dataType:'text',success:function(count){
            $('.'+obj).find('.count').text(count);
        }});
    }
}

/* 视频照片版块收藏 */
function collection(){
    var title="鸡蛋美术商城-美术用品专卖店-圆梦美院计划";
    var url="http://www.eggms.com/freeplan.php";
    if(window.sidebar){
        try{
            window.sidebar.addPanel(title,url,'');
        }catch(e){
            alert("您的浏览器不支持该功能,请使用Ctrl+D收藏本页");
        }
    }else{
        try{
            window.external.AddFavorite(url,title);
        }catch(e){
            alert("您的浏览器不支持该功能,请使用Ctrl+D收藏本页");
        }
    }
}

/* 视频照片版块照片弹出相册 */
$(document).ready(function(){
    var scrollImage = {
        //图片的数量
        num : parseInt('17'),
        //图片src地址数组，对应图片num
        url : ["../themes/default/pic/video_photo_bigimg1.jpg",
                "../themes/default/pic/video_photo_bigimg2.jpg",
                "../themes/default/pic/video_photo_bigimg3.jpg",
                "../themes/default/pic/video_photo_bigimg4.jpg",
                "../themes/default/pic/video_photo_bigimg5.jpg",
                "../themes/default/pic/video_photo_bigimg6.jpg",
                "../themes/default/pic/video_photo_bigimg7.jpg",
                "../themes/default/pic/video_photo_bigimg8.jpg",
                "../themes/default/pic/video_photo_bigimg9.jpg",
                "../themes/default/pic/video_photo_bigimg10.jpg",
                "../themes/default/pic/video_photo_bigimg11.jpg",
                "../themes/default/pic/video_photo_bigimg12.jpg",
                "../themes/default/pic/video_photo_bigimg13.jpg",
                "../themes/default/pic/video_photo_bigimg14.jpg",
                "../themes/default/pic/video_photo_bigimg15.jpg",
                "../themes/default/pic/video_photo_bigimg16.jpg",
                "../themes/default/pic/video_photo_bigimg17.jpg"],
        //图片描述desc
        desc : ["（四川美术学院）其实大学不是放松自己的地方，而是追逐梦想的开始。","（中央美术学院）想想高三那段日子真是挺痛苦的，但不逼一下自己，怎么知道自己多牛逼呢？","（广州美术学院）来广美吧！这里的饭堂很好吃！","（广州美术学院）毕业了,才发现大学生是最好的职业。","（西安美术学院）抱着一张大学录取通知书来睡觉，醒来后发现通知书变成了毕业证，证明我曾经在这里睡过。","（鲁迅美术学院）上了美院才知道，原来班主任到毕业都见不了几次。","（湖北美术学院）真怀念高三那段日子，但不要让我再来一次了。","（天津美术学院）美院也没什么不一样，也有混日子的，也有学霸，看你怎么过了。","（清华大学美术学院）在美院里面更自由一些，厉害的人更多一些，自己都不敢懒惰了。","（天津美术学院）高三的学弟学妹们，加油！","（西安美术学院）上了大学一定要多交朋友，多谈恋爱，哈哈！","（四川美术学院）大学跟高三有所不同的只是没老师逼着你去做卷子了而已。","（中国美术学院）国美真的很漂亮，真庆幸自己能考上国美，师弟师妹都来考国美吧！","（天津美术学院）有空来天美看看，你一定会想考这样的大学的。","（湖北美术学院）加油！加油！","（广州美术学院）考大学一定要考自己喜欢的，报专业一定要报自己感兴趣的","（鲁迅美术学院）报名圆梦美院计划，考上美院真的退钱哦！"],
        //下边一栏所需参数
        //当前图片
        //因为当前图片的num是会随着按钮点击而变化，点击向左的num-1，点击向右的num+1，n代表num
        currentNum : function(n){
            if(n>0){
                return $('.img_number').find('.cur_num').eq(0).text(n);
            }else{
                return parseInt($('.img_number').find('.cur_num').eq(0).text());
            }     
        },
        //下边一栏左右按钮的样式,同上moveClass()类似
        changeClass : function(pre, next){
            var preClass = pre ? 'f_p_prev' : 'f_p_prev_disabled';
            var nextClass = next ? 'f_p_next' : 'f_p_next_disabled';
            $('.btn_left_area a').removeClass().addClass(preClass);
            $('.btn_right_area a').removeClass().addClass(nextClass);
        },
        //下边一栏左右按钮点击,这里左右按钮给和在一起了。通过direction来判断
        //有两种极端情况，第一种是：第一张图片。第二种是：最后一张图片。
        change : function(direction) {
            if(direction == 'pre' && this.currentNum() > 1){
                //获得当前之前的图片num
                var willNum = this.currentNum() - 1;
                //改变页面图片num数字及其src地址
                this.changeNum(willNum);
            }else if(direction == 'next' && this.currentNum() < this.num){
            //获得当前之后的图片num
               var willNum = this.currentNum() + 1;
               //改变页面图片num数字及其src地址
               this.changeNum(willNum);
            }
        },
        //改变图片src及其num数字
        changeNum : function (willNum){
            //改变图片数字
            this.currentNum(willNum);
            //改变图片src地址
            $('#big_image').attr('src', this.url[willNum-1]);
            //改变图片desc描述
            $('#big_image').next().text(this.desc[willNum-1]);
             
            //判断左右按钮是否变灰
            //两种极端状态,第一张和最后一张
            //判断总的图片数量
            if(willNum == 1){
               if(this.num > 1){return this.changeClass(0, 1)}
             }else if(willNum == this.num){
               if(this.num > 1){return this.changeClass(1, 0)}
            }else{
               if(this.num > 1){return this.changeClass(1, 1)}
            }
        } 
    }

    $(document).ready(function(){
        //判断图片数量是否大于0,只有大于0才能实现轮播的一些功能。
        if(scrollImage.num > 0){
        //判断图片数量是否小于等于1,true时,下边一栏的左右按钮变灰不可用。
        if(scrollImage.num <= 1){
            scrollImage.changeClass(0, 0);  //这样左右按钮都变灰
        }
            
        //下边一栏图片的改变：其实也就是图片的src地址改变而已，点击按钮改变src地址
        //假如点击按钮我们能获取这应该是第几张图片，这样我们就能把图片的src地址写入到一个数组
        //数组的键是当前图片的num，值是src，这样就能点击按钮，加载相应的图片了。
        //点击下边一栏的左按钮,点击时当前图片-1,就是前面的图片
        $('.btn_left_area a').click(function(){
            scrollImage.change('pre');  
        });
            
        //点击下边一栏的右按钮,点击时当前图片+1,就是后面的图片
        $('.btn_right_area a').click(function(){
            scrollImage.change('next'); 
        });
            
        //点击上边一栏的图片  img[currentNum]表示上边一栏的img元素
        $('img[currentNum]').click(function(){
            //获得当前图片的num
            var willNum = parseInt($(this).attr('currentNum'));
            scrollImage.changeNum(willNum);
        })

        $("#video_photo li").click(function(){
            $("#flow_pohto").show();
            $("#video_bg").show();
            $("#close_flow_pohto").show();
        });
        $("#close_flow_pohto").click(function(){
            $("#flow_pohto").hide();
            $("#video_bg").hide();
            $("#close_flow_pohto").hide();
        });

    }
    })
});


/* 视频照片版块点击视频弹出 */
$(document).ready(function(){
    $("#video_photo .video_photo_video").click(function(){
        var video1_src = "http://player.youku.com/player.php/sid/XNDI1NDU2MjA0/v.swf";
        var video2_src = "http://player.youku.com/player.php/sid/XNjM1MjYwOTky/v.swf";
        var video3_src = "http://player.youku.com/player.php/sid/XNzM0Njc3OTM2/v.swf";
        var att = $(this).attr('att');
        if(att == 'video_photo_video1'){
            $("#video").attr('src', video1_src);
        }else if(att == 'video_photo_video2'){
            $("#video").attr('src', video2_src);
        }else if(att == 'video_photo_video3'){
            $("#video").attr('src', video3_src);
        }
        $("#video_bg").show();
        $("#video").show();
        $("#close_video").show();
    });            
    $("#close_video").click(function(){
        $("#video_bg").hide();
        $("#video").hide();
        $("#close_video").hide();
    });

    /* 鼠标移动显示照片介绍内容 */
    $("#video_photo li").hover(function(){
        var imgclass = $(this).attr('class');
        if(imgclass == "video_photo_img1"){
            $("#video_photo .video_photo_img1 .text_bg").animate({"bottom":"-15px"},70);
        }else if(imgclass == "video_photo_img2"){
            $("#video_photo .video_photo_img2 .text_bg").animate({"bottom":"-15px"},70);
        }
        else if(imgclass == "video_photo_img2"){
            $("#video_photo .video_photo_img2 .text_bg").animate({"bottom":"-15px"},70);
        }
        else if(imgclass == "video_photo_img3"){
            $("#video_photo .video_photo_img3 .text_bg").animate({"bottom":"-15px"},70);
        }
        else if(imgclass == "video_photo_img4"){
            $("#video_photo .video_photo_img4 .text_bg").animate({"bottom":"-15px"},70);
        }
        else if(imgclass == "video_photo_img5"){
            $("#video_photo .video_photo_img5 .text_bg").animate({"bottom":"-15px"},70);
        }
        else if(imgclass == "video_photo_img6"){
            $("#video_photo .video_photo_img6 .text_bg").animate({"bottom":"-15px"},70);
        }
        else if(imgclass == "video_photo_img7"){
            $("#video_photo .video_photo_img7 .text_bg").animate({"bottom":"-15px"},70);
        }
        else if(imgclass == "video_photo_img8"){
            $("#video_photo .video_photo_img8 .text_bg").animate({"bottom":"-15px"},70);
        }
        else if(imgclass == "video_photo_img9"){
            $("#video_photo .video_photo_img9 .text_bg").animate({"bottom":"-15px"},70);
        }else if(imgclass == "video_photo_img10"){
            $("#video_photo .video_photo_img10 .text_bg").animate({"bottom":"-15px"},70);
        }
    },function(){
        $("#video_photo li .text_bg").animate({"bottom":"-78px"},70);
    });
});


/* 九大美院内容显示内容 */
$(document).ready(function(){
    //鼠标移经过
    $("#arts_academy__praise .box_list .big_box").hover(function(){
        var c = $(this).attr('att');   //当前盒子的属性值
        var index = $(this).index()+1;   //当前盒子的下标
        var num = parseInt((index-1)/3);
        var html = $("#arts_academy__praise .window_pic .content").eq(index-1).html();
        $("#arts_academy__praise .window").stop(true).css({'top':259+205*num+'px','display':'block'}).animate({'opacity':1},0);
        $("#arts_academy__praise .window .text").html(html);
        $("#arts_academy__praise .thumb img").each(function(i,j){
            $(this).attr('src', '../themes/default/pic/'+c+'_w'+(i+1)+'.jpg');
        });
        $("#arts_academy__praise .big_img img").attr('src', '../themes/default/pic/'+c+'_w1.jpg');
        $("#arts_academy__praise .thumb img").mouseenter(function(){
            $("#arts_academy__praise .big_img img").attr('src', $(this).attr('src'));
        });
        //鼠标离开
        },function(){
            var c = $(this).attr('att');
            $("#arts_academy__praise .window").animate({'opacity':0},0,function(){$(this).hide();});
            $("#arts_academy__praise .window").hover(function(){
                $(this).stop();
            $("#arts_academy__praise .window").animate({'opacity':1},0);
        },function(){
            $("#arts_academy__praise .window").animate({'opacity':0},0,function(){$(this).hide();});
        });  
    });
});


/* 授权证书轮播特效JS */
function ZoomPic (){
    this.initialize.apply(this, arguments)  
}
ZoomPic.prototype = {
    initialize : function (id){
        var _this = this;
        this.wrap = typeof id === "string" ? document.getElementById(id) : id;
        this.oUl = this.wrap.getElementsByTagName("ul")[0];
        this.aLi = this.wrap.getElementsByTagName("li");
        this.prev = this.wrap.getElementsByTagName("pre")[0];
        this.next = this.wrap.getElementsByTagName("pre")[1];
        this.timer = null;
        this.aSort = [];
        this.iCenter = 4;
        this._doPrev = function () {return _this.doPrev.apply(_this)};
        this._doNext = function () {return _this.doNext.apply(_this)};
        this.options = [
            {width:100, height:120, top:91, left:154, zIndex:1},
            {width:120, height:150, top:71, left:134, zIndex:1},
            {width:132, height:189, top:62, left:0, zIndex:2},
            {width:163, height:234, top:40, left:109, zIndex:3},
            {width:224, height:314, top:0, left:252, zIndex:4},
            {width:163, height:234, top:40, left:448, zIndex:3},
            {width:132, height:189, top:62, left:597, zIndex:2},
            {width:120, height:150, top:71, left:496, zIndex:1},
            {width:100, height:120, top:91, left:154, zIndex:1}
        ];
        for (var i = 0; i < this.aLi.length; i++) this.aSort[i] = this.aLi[i];
        this.aSort.unshift(this.aSort.pop());
        this.setUp();
        this.addEvent(this.prev, "click", this._doPrev);
        this.addEvent(this.next, "click", this._doNext);
        this.doImgClick();      
        this.timer = setInterval(function (){
            _this.doNext()  
        }, 3000);       
        this.wrap.onmouseover = function (){
            clearInterval(_this.timer)  
        };
        this.wrap.onmouseout = function (){
            _this.timer = setInterval(function (){
                _this.doNext()  
            }, 3000);   
        }
    },
    doPrev : function (){
        this.aSort.unshift(this.aSort.pop());
        this.setUp()
    },
    doNext : function (){
        this.aSort.push(this.aSort.shift());
        this.setUp()
    },
    doImgClick : function (){
        var _this = this;
        for (var i = 0; i < this.aSort.length; i++){
            this.aSort[i].onclick = function (){
                if (this.index > _this.iCenter){
                    for (var i = 0; i < this.index - _this.iCenter; i++) _this.aSort.push(_this.aSort.shift());
                    _this.setUp()
                }
                else if(this.index < _this.iCenter){
                    for (var i = 0; i < _this.iCenter - this.index; i++) _this.aSort.unshift(_this.aSort.pop());
                    _this.setUp()
                }
            }
        }
    },
    setUp : function (){
        var _this = this;
        var i = 0;
        for (i = 0; i < this.aSort.length; i++) this.oUl.appendChild(this.aSort[i]);
        for (i = 0; i < this.aSort.length; i++){
            this.aSort[i].index = i;
            if (i < 9){
                this.css(this.aSort[i], "display", "block");
                this.doMove(this.aSort[i], this.options[i], function (){
                    _this.doMove(_this.aSort[_this.iCenter].getElementsByTagName("img")[0], {opacity:100}, function (){
                        _this.doMove(_this.aSort[_this.iCenter].getElementsByTagName("img")[0], {opacity:100}, function (){
                            _this.aSort[_this.iCenter].onmouseover = function (){
                                _this.doMove(this.getElementsByTagName("div")[0], {bottom:0})
                            };
                            _this.aSort[_this.iCenter].onmouseout = function (){
                                _this.doMove(this.getElementsByTagName("div")[0], {bottom:-100})
                            }
                        })
                    })
                });
            }
            else{
                this.css(this.aSort[i], "display", "none");
                this.css(this.aSort[i], "width", 0);
                this.css(this.aSort[i], "height", 0);
                this.css(this.aSort[i], "top", 37);
                this.css(this.aSort[i], "left", this.oUl.offsetWidth / 2)
            }
            if (i < this.iCenter || i > this.iCenter){
                this.css(this.aSort[i].getElementsByTagName("img")[0], "opacity", 30)
                this.aSort[i].onmouseover = function (){
                    _this.doMove(this.getElementsByTagName("img")[0], {opacity:100})    
                };
                this.aSort[i].onmouseout = function (){
                    _this.doMove(this.getElementsByTagName("img")[0], {opacity:35})
                };
                this.aSort[i].onmouseout();
            }
            else{
                this.aSort[i].onmouseover = this.aSort[i].onmouseout = null
            }
        }       
    },
    addEvent : function (oElement, sEventType, fnHandler){
        return oElement.addEventListener ? oElement.addEventListener(sEventType, fnHandler, false) : oElement.attachEvent("on" + sEventType, fnHandler)
    },
    css : function (oElement, attr, value){
        if (arguments.length == 2){
            return oElement.currentStyle ? oElement.currentStyle[attr] : getComputedStyle(oElement, null)[attr]
        }
        else if (arguments.length == 3){
            switch (attr){
                case "width":
                case "height":
                case "top":
                case "left":
                case "bottom":
                    oElement.style[attr] = value + "px";
                    break;
                case "opacity" :
                    oElement.style.filter = "alpha(opacity=" + value + ")";
                    oElement.style.opacity = value / 100;
                    break;
                default :
                    oElement.style[attr] = value;
                    break
            }   
        }
    },
    doMove : function (oElement, oAttr, fnCallBack){
        var _this = this;
        clearInterval(oElement.timer);
        oElement.timer = setInterval(function (){
            var bStop = true;
            for (var property in oAttr){
                var iCur = parseFloat(_this.css(oElement, property));
                property == "opacity" && (iCur = parseInt(iCur.toFixed(2) * 100));
                var iSpeed = (oAttr[property] - iCur) / 5;
                iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
                
                if (iCur != oAttr[property]){
                    bStop = false;
                    _this.css(oElement, property, iCur + iSpeed)
                }
            }
            if (bStop){
                clearInterval(oElement.timer);
                fnCallBack && fnCallBack.apply(_this, arguments)    
            }
        }, 30)
    }
};
window.onload = function (){
    new ZoomPic("box");
};